package com.ruoyi.web.controller.custom;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.custom.domain.Loan;
import com.ruoyi.custom.service.ILoanService;

/**
 * 客户放款Controller
 *
 * @author ruoyi
 * @date 2025-07-25
 */
@Api(tags = "客户放款")
@RestController
@RequestMapping("/custom/loan")
public class LoanController extends BaseController
{
    @Autowired
    private ILoanService loanService;

    /**
     * 查询客户放款列表
     */
    @ApiOperation("查询客户放款列表分页")
    @PreAuthorize("@ss.hasPermi('custom:loan:list')")
    @GetMapping("/list")
    public TableDataInfo list(Loan loan)
    {
        startPage();
        List<Loan> list = loanService.selectLoanList(loan);
        return getDataTable(list);
    }

    /**
     * 导出客户放款列表
     */
    @PreAuthorize("@ss.hasPermi('custom:loan:export')")
    @Log(title = "客户放款", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response,Loan loan)
    {
        List<Loan> list = loanService.selectLoanList(loan);
        ExcelUtil<Loan> util = new ExcelUtil<Loan>(Loan.class);
         util.exportExcel(response,list, "放款数据");
    }

    /**
     * 获取客户放款详细信息
     */
    @ApiOperation("获取客户放款详细信息")
    @PreAuthorize("@ss.hasPermi('custom:loan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(loanService.selectLoanById(id));
    }

    /**
     * 新增客户放款
     */
    @ApiOperation("新增客户放款")
    @PreAuthorize("@ss.hasPermi('custom:loan:add')")
    @Log(title = "客户放款", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Loan loan)
    {
        return toAjax(loanService.insertLoan(loan));
    }

    /**
     * 修改客户放款
     */
    @ApiOperation("修改客户放款")
    @PreAuthorize("@ss.hasPermi('custom:loan:edit')")
    @Log(title = "客户放款", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Loan loan)
    {
        return toAjax(loanService.updateLoan(loan));
    }

    /**
     * 删除客户放款
     */
    @ApiOperation("删除客户放款")
    @PreAuthorize("@ss.hasPermi('custom:loan:remove')")
    @Log(title = "客户放款", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(loanService.deleteLoanByIds(ids));
    }
}
